/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package project.jpdftools.ui.keylisteners;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import project.jpdftools.ui.logic.JPDF;
import project.jpdftools.ui.logic.JPDFText;

/**
 *
 * @author Mido
 */
public class ShortcutsAction implements KeyListener {

    private JPDF component;

    public ShortcutsAction(JPDF component) {
        super();
        this.component = component;
    }

    public void keyTyped(KeyEvent e) {
    }

    public void keyPressed(KeyEvent e) {
        if (component instanceof JPDFText) {
            JPDFText text = (JPDFText) component;
            if (Character.isLetter(e.getKeyChar())) {
                text.getMiUndo().setEnabled(true);
            } // undo shortcut
            else if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK && e.getKeyCode() == KeyEvent.VK_Z) {
                text.getMiUndo().doClick();
            } // redo shortcut
            else if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK && e.getKeyCode() == KeyEvent.VK_Y) {
                text.getMiRedo().doClick();
            } // remove shortcut
            else if ((e.getModifiers() & KeyEvent.SHIFT_MASK) == KeyEvent.SHIFT_MASK && e.getKeyCode() == KeyEvent.VK_DELETE) {
                text.getMiRemoveComponent().doClick();
            } // align center shortcut
            else if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK && e.getKeyCode() == KeyEvent.VK_E) {
                text.getMiAlignCenter().doClick();
            } // align left shortcut
            else if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK && e.getKeyCode() == KeyEvent.VK_L) {
                text.getMiAlignLeft().doClick();
            } // align right shortcut
            else if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK && e.getKeyCode() == KeyEvent.VK_R) {
                text.getMiAlignRight().doClick();
            } // border color shortcut
            else if ((e.getModifiers() & (KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)) == (KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)
                    && e.getKeyCode() == KeyEvent.VK_B) {
                text.getMiBorderColor().doClick();
            } // fill color shortcut
            else if ((e.getModifiers() & (KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)) == (KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)
                    && e.getKeyCode() == KeyEvent.VK_I) {
                text.getMiFillColor().doClick();
            } // font color shortcut
            else if ((e.getModifiers() & (KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)) == (KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)
                    && e.getKeyCode() == KeyEvent.VK_T) {
                text.getMiFontColor().doClick();
            } // font properties shortcut
            else if ((e.getModifiers() & (KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)) == (KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)
                    && e.getKeyCode() == KeyEvent.VK_F) {
                text.getMiFontProperties().doClick();
            } // show border shortcut
            else if ((e.getModifiers() & (KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)) == (KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)
                    && e.getKeyCode() == KeyEvent.VK_H) {
                text.getMiShowBorder().doClick();
            }
        }
    }

    public void keyReleased(KeyEvent e) {
    }
}
